// pages/index/report.js
const app = getApp()
const nt_util = require('../../utils/nt_util.js')
Page({
  data: {
    array: ['不提供本区域服务', '服务技能不够', '服务态度差', '联系方式失效', '不能按时提供服务', '其他'],
    objectArray: [
      {
        id: 0,
        name: '不提供本区域服务'
      },
      {
        id: 1,
        name: '服务技能不够'
      },
      {
        id: 2,
        name: '服务态度差'
      },
      {
        id: 3,
        name: '联系方式失效'
      },
      {
        id: 4,
        name: '不能按时提供服务'
      },
      {
        id: 5,
        name: '其他'
      }
    ],
    index: 0,
    btn_saveFeedBack: false,
    question: '',
    content: '',
    phone: ''
  },
  onLoad: function (options) {
  },
  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value,
      question: this.data.array[e.detail.value]
    })
  },
  saveFeedBack: function (e) {
    var that = this;
    if (!that.checkParams()) {
      return false;
    };

    if (that.data.btn_saveFeedBack) {
      wx.showModal({
        title: '提示',
        content: '您已提交！',
        showCancel: false,
        success: function (res) {
        }
      })
      return false;
    };
    that.setData({
      btn_saveFeedBack: true,
    });
    
    nt_util.httpRequest('api/life/v1/saveFeedBack', 'POST', {
      
      question: that.data.question,
      content: that.data.content,
        phone: that.data.phone,
    }, function (res) {
      that.setData({
        question: '',
        phone: ''
      });
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 1500,
        complete: function (res) {
          setTimeout(function () {
            wx.switchTab({
              url: '/pages/index/index'
            })
          }, 1500);
        }
      })
    });
  },
  checkParams: function () {
    var that = this;
    if (that.data.question =='其他'){
    if (!that.data.content) {
      wx.showToast({
        title: '详细信息不能为空',
        icon: 'none'
      })
      return false;
      }
    }
    if (!that.data.phone) {
      wx.showToast({
        title: '电话/QQ/微信，不能为空',
        icon: 'none'
      })
      return false;
    }
    return true;
  },
  bindKeyInput: function (e) {
    var that = this;
    var dataset = e.currentTarget.dataset;
    var data_type = e.detail.value;
    switch (dataset.type) {
      case 'content':
        that.setData({
          content: data_type
        });
        break;
      case 'phone':
        that.setData({
          phone: data_type
        });
        break;
    }
  }
})